﻿using Acme.SmartWMS.Outbound;
using Acme.SmartWMS.Outbound.CustomerShipmentService;
using Acme.SmartWMS.Outbound.CustomerShipmentService.DTO;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace Acme.SmartWMS.Web.Controllers.Outbound
{
    public class CustomerShipmentController : Controller
    {
        /// <summary>
        /// 客户出货仓储
        /// </summary>
        private readonly ICustomerShipmentAppService _customerShipmentAppService;
        public CustomerShipmentController(ICustomerShipmentAppService customerShipmentAppService)
        {
            _customerShipmentAppService = customerShipmentAppService;
        }

        public IActionResult CustomerShipmentList()
        {
            return View();
        }
        public IActionResult Add()
        {
            return View();
        }
        public IActionResult Update(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 获取客户出货显示 查询 分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="shipmentNumber"></param>
        /// <param name="productCode"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetCustomerShipmentList(int page, int limit, string? shipmentNumber, string? productCode)
        {
            var customerShipment=await _customerShipmentAppService.GetCustomerShipmentList(page, limit, shipmentNumber, productCode);
            return Json(new {code=0,data=customerShipment.Queryable,count=customerShipment.RowCount });
        }
        /// <summary>
        /// 添加客户出货
        /// </summary>
        /// <param name="customerShipmentDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddCustomerShipment(CustomerShipmentDTO customerShipmentDTO)
        {
            return await _customerShipmentAppService.AddCustomerShipment(customerShipmentDTO);
        }
        /// <summary>
        /// 删除客户出货
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteCustomerShipment(string ids)
        {
            return await _customerShipmentAppService.DeleteCustomerShipment(ids);
        }
        /// <summary>
        /// 获取客户出货主键Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<CustomerShipment> GetCustomerShipmentById(int id)
        {
            ViewBag.Id = id;
            return await _customerShipmentAppService.GetCustomerShipmentById(id);
        }
        /// <summary>
        /// 更新客户出货
        /// </summary>
        /// <param name="customerShipmentDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateCustomerShipment(CustomerShipmentDTO customerShipmentDTO)
        {
            return await _customerShipmentAppService.UpdateCustomerShipment(customerShipmentDTO);
        }
    }
}
